﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="KarrIsikuValjavote", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(KarrIsikuValjavote))]
    public class KarrIsikuValjavoteSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKarrIsikuValjavote clazz;
        
        public KarrIsikuValjavoteSerializer(IKarrIsikuValjavote clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Isik!=null) {
                Writer.WriteStartElement("Isik");
                global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData(clazz.Isik);
                Writer.WriteTypeAttribute(metaIsik.TypeQualifiedName.Namespace, metaIsik.TypeQualifiedName.Name);
                metaIsik.NewSerializer(clazz.Isik).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.PdfFailiObjektID!=null) {
                Writer.WriteStartElement("PdfFailiObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.PdfFailiObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ParinguID!=null) {
                Writer.WriteStartElement("ParinguID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ParinguID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Valideeritud!=null) {
                Writer.WriteStartElement("Valideeritud");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Valideeritud))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Isik") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IIsik>(Reader, "Isik", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                    clazz.Isik = metaIsik.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IIsik>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Isik");
                        metaIsik.NewSerializer(clazz.Isik).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="PdfFailiObjektID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>KarrIsikuValjavote>PdfFailiObjektID");
                }
                clazz.PdfFailiObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("PdfFailiObjektID")).Value;
            }
            if (Reader.LocalName=="ParinguID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>KarrIsikuValjavote>ParinguID");
                }
                clazz.ParinguID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ParinguID")).Value;
            }
            if (Reader.LocalName=="Valideeritud") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Valideeritud = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("Valideeritud")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
